%removal fringe of photo using new methods

addpath(genpath('\\WEI-PC\ChangruiYi\Rb87Programs\RemoveBackground\'));
folderName='\\BEC-DELL\ShareFolder\20170902morning\ikon-17639\';
refimagesIniDirectory='\\WEI-PC\ChangruiYi\Rb87Programs\RemoveBackground\refimagesIni.mat';
photoNamePre='17639test_';
filename_pre='ascOD17639test_';

bgmask2=ones(1024,1024);
bgmask3=-ones(1024,1024);
bgmask1=zeros(1024,1024);

photoInd=7;
refNum=250;
refimagesIniStruct=load(refimagesIniDirectory);
refimagesIni=refimagesIniStruct.refimagesIni;

if size(refimagesIni,3)==refNum
    refimages=refimagesIni;
else
    error('Error: refNum ~= loaded reference images');
end

files_if=[photoInd photoInd];
[image]=drawpicture(folderName,filename_pre,files_if,'1picture');
figure(1);imagesc(image(1).data,[-0.2,0.1]);title(num2str(photoInd));

absimages=loadPhoto(photoName(folderName,photoNamePre,photoInd,'.asc'));
refimages=loadPhoto(photoName(folderName,photoNamePre,photoInd,'bg.asc'));
nolimage=loadPhoto(photoName(folderName,photoNamePre,photoInd,'nolight.asc'));

ROI=[100 160 550 500];
ROI1=[70 100 800 800];
ROIX_vector=ROI(1):(ROI(1)+ROI(3));
ROIY_vector=ROI(2):(ROI(2)+ROI(4));
ROIX_vector1=ROI1(1):(ROI1(1)+ROI1(3));
ROIY_vector1=ROI1(2):(ROI1(2)+ROI1(4));
bgmask3(ROIY_vector,ROIX_vector)=-2;
bgmask1(ROIY_vector1,ROIX_vector1)=1;
bgmask=bgmask1+bgmask2+bgmask3;
rectangle('position',[ROI(1),ROI(2),ROI(3),ROI(4)],'Curvature',[1,0],  'EdgeColor',[0 0 0]);
rectangle('position',[ROI1(1),ROI1(2),ROI1(3),ROI1(4)],'Curvature',[1,0],  'EdgeColor',[0 0 0]);
RemoveFringe(refimages,bgmask);